package com.hardydou.agent;

import com.sun.tools.attach.*;

import java.io.IOException;
import java.util.List;

/**
 * @author ：hardy
 * @description：main
 * @date ：Created in 2020/7/6
 * @Copyright ：Hardydou.com
 */
public class Main {

    /***
     * 测试前置Agent<br/>
     * vm 添加参数：-javaagent:$ModuleFileDir$/out/artifacts/agent/agent.jar=sssss
     * <br/>
     * 先启动 ForkJoinTest
     * <br/>
     *
     * @param args
     * @throws IOException
     * @throws AttachNotSupportedException
     * @throws AgentLoadException
     * @throws AgentInitializationException
     */
    public static void main(String[] args) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException {
        List<VirtualMachineDescriptor> vms = VirtualMachine.list();
        for (VirtualMachineDescriptor vm : vms) {
            if (vm.displayName().contains("ForkJoinTest")) {
                VirtualMachine target = VirtualMachine.attach(vm.id());
                target.loadAgent("/Users/hardy/Documents/work/try-space/learn-java/out/artifacts/agent/agent.jar");
            }
        }

    }
}
